﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Index_Ajax.ascx.cs" Inherits="Toolkit.Web.Examples.DataGrid.Index_Ajax" %>
<%@ Import Namespace="Toolkit.Web" %>
<%@ Import Namespace="Toolkit.Web.ViewComponents" %>
<%@ Import Namespace="Toolkit.Web.ViewComponents.DataGrid" %>

<%
    this.Toolkit().DataGrid<Toolkit.Web.Examples.DataGrid.Index.GridEntry>(Model)
        .Columns(columns =>
        {
            columns.AddCheckBoxColumn(true, 31).Filter(t => "&nbsp;").Footer(t => "&nbsp;");
            //columns.AddChildRowToggleColumn(31).Filter(t => "&nbsp;").Footer(t => "&nbsp;");
            columns.AddIndexColumn(31).Filter(t => "&nbsp;").Footer(t => "&nbsp;");
            columns.AddColumn("c0").Header(h => "Column 0").Body(item => item.Column0).Footer(f => "Column 0").Filter(f => "Filter");
            columns.AddColumn("c1").Header(h => "Column 1").Body(item => item.Column1).Footer(f => "Column 1").Filter(f => "Filter").Label("Column 1 (uno)").Sorting(true).Resizing(true).Menu(true).HidingAndShowing(true);
            columns.AddColumn("c2").Header(h => "Column 2").Body(item => item.Column2).Footer(f => "Column 2").Filter(f => "Filter").Sorting(true).Resizing(true).Menu(true).HidingAndShowing(true);
            columns.AddColumn("c3").Header(h => "Column 3").Body(item => item.Column3).Footer(f => "Column 3").Filter(f => "Filter").Sorting(true).Resizing(true).Menu(true).HidingAndShowing(true);
            columns.AddColumn("c4").Header(h => "Column 4").Body(item => item.Column4).Footer(f => "Column 4").Filter(f => "Filter").Menu(true);
            columns.AddColumn("c5").Header(h => "Column 5").Body(item => item.Column5).Footer(f => "Column 5").Filter(f => "Filter").Sorting(true);
            columns.AddColumn("c6").Header(h => "Column 6").Body(item => item.Column6).Footer(f => "Column 6").Filter(f => "Filter").Resizing(true);
            columns.AddColumn("c7").Header(h => "Column 7").Body(item => item.Column7).Footer(f => "Column 7").Filter(f => "Filter").Menu(true).HidingAndShowing(true).AddMenuSection((grid, writer) => { writer.Write("Hello World!"); });
            columns.AddColumn("c8").Header(h => "Column 8").Body(item => item.Column8).Footer(f => "Column 8").Filter(f => "Filter");
            columns.AddColumn("c9").Header(h => "Column 9").Body(item => item.Column9).Footer(f => "Column 9").Filter(f => "Filter");

            //for (int i = 0; i < 40; i++)
            //{
            //    columns.AddColumn("d" + i).Menu(true).HidingAndShowing(true);
            //}

            //columns.AddColumn("ww").WordWrap(true);
        })
        .NoResultsMarkup(t => "No records found.")
        .ColumnWidth(100, null, null)
        .Header(grid => "Header of Grid")
        .ViewPort(true, 400, null)
        .RowAction(row =>
        {
            row.Key = string.Format("r{0}", row.Index);
        })
        .DefaultColumnHeader(h => "Default Header")
        .DefaultColumnFilter(h => "Default Filter")
        .DefaultColumnBody(h => "Default Body - this is long text that may get cut off depending on column width")
        .DefaultColumnFooter(h => "Default Footer")
        //.DefaultColumnEditor(e => "Editor")
        .AddAdditionalHiddenMarkup(h => "Hidden Tag 1")
        .AddAdditionalHiddenMarkup(h => "Hidden Tag 1")
        .AddAdditionalHiddenMarkup(h => "<input type='hidden' name='Test.Name' value='hello world' />")
        .ClientEventHandlers(handlers =>
        {
            handlers.OnAfterLoad = "test_OnAfterLoad";
            handlers.OnBeforeDataBind = "test_OnBeforeDataBind";
            //handlers.OnDataBindOverride = "test_OnDataBindOverride";
            handlers.OnAfterDataBind = "test_OnAfterDataBind";
            handlers.OnBeforeDisplayChange = "test_OnBeforeDisplayChange";
            handlers.OnAfterDisplayChange = "test_OnAfterDisplayChange";
            handlers.OnAfterRowSelectionChange = "test_OnAfterRowSelectionChange";
        })
        .ColumnMenus(true, null)
        .ColumnHidingAndShowing(true, true)
        .ColumnSorting("c2", false)
        .ColumnResizing(true, null, null)
        .ColumnReordering(true)
        .AddMenuSection((grid, writer) =>
        {
            writer.Write(grid.MenuHelper.ColumnSortDirectionSection());
        })
        .AddMenuSection((grid, writer) =>
        {
            writer.Write(grid.MenuHelper.ColumnVisibilitySection());
        })
        .ErrorLoadingDataMarkup(t => "Error loading data...")
        .DataBinding(true, "post", "/DataGrid/AjaxHandler.aspx")
        .Pagination(DataGridPagingType.VirtualPaging, null, null, null)
        .RowHeight(25, null)
        .PageSizeOptions(50, 100, 250, 500)
        .Footer((grid, writer) =>
        {
            writer.Write("<div style='float:left;'>");
            writer.Write("Footer of Grid");
            writer.Write("</div>");

            writer.Write("<div style='float:right;'>");
            writer.Write(grid.ResetHelper.DefaultResetTrigger());
            writer.Write("</div>");

            if ((grid.Settings.PagingType == DataGridPagingType.BufferedPaging || grid.Settings.PagingType == DataGridPagingType.DefaultPaging) && grid.DataSource != null && grid.DataSource.Count() > 0)
            {
                writer.Write("<div style='float:right;'>");
                writer.Write(string.Format("<div style='float:left;margin: 2px 0 0 2em;'>Page Size:</div><div style='float:left;'>{0}</div>", grid.PaginationHelper.DefaultPageSizeSelector().ToHtmlString()));
                writer.Write("</div>");

                writer.Write("<div style='float:right;'>");
                writer.Write(grid.PaginationHelper.DefaultPageIndexSelector(3).ToHtmlString());
                writer.Write("</div>");
            }
        })
        .PersistSettings(false, "/DataGrid/AjaxHandler.aspx?savePrefs=True", Model.PersistenceKey)
        //.ChildRowAction(row => {
        //    row.SetTemplate(item => string.Format("<div>Hello World!</div><div>{0}</div>", item.Column0));
        //    row.Conditional = item => row.IsAlternate;
        //})
        .Render();
%>